<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<div class="line-big">
	<div class="xl2"></div>
	<div class="xl8">
		<div class="panel border-back" id="write_express_info_div">
			<div class="panel-body text-center">
				<h1>
					<strong>派送订单</strong>
				</h1>
			</div>
			<div class="panel-foot bg-white border-back">
				<input type="hidden" id="express_order_id_input" value="${param.id }">
				<div class="form-group">
					<div class="label">
						<label for="orderExpressCompany">*快递公司名称(2-50个字)</label>
					</div>
					<div class="field">
						<select class="input" id="orderExpressCompany" data-regex="^\S.{0,48}\S$">
							<option value="EMS">EMS</option>
							<option value="顺丰速运">顺丰速运</option>
							<option value="中通快递">中通快递</option>
							<option value="圆通速递">圆通速递</option>
							<option value="韵达快运">韵达快运</option>
							<option value="天天快递">天天快递</option>
							<option value="百世汇通">百世汇通</option>
							<option value="宅急送">宅急送</option>
							<option value="申通快递">申通快递</option>
							<option value="优速快递">优速快递</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label for="orderExpressNumber">*快递公司单号(2-50个字)</label>
					</div>
					<div class="field">
						<input type="text" class="input" value="" id="orderExpressNumber" data-regex="^\S.{0,48}\S$" />
					</div>
				</div>
			</div>
			<div class="panel-foot bg-white">
				<div class="line-big margin-top margin-bottom">
					<div class="xl4"></div>
					<div class="xl4 text-center">
						<button class="button border-blue" id="submit_send_out_order_button">提交快递信息</button>
					</div>
					<div class="xl4"></div>
				</div>
			</div>
		</div>
		<div id="add_success_div" class="G-MarginTop100" style="display: none;">
			<div class="line-big">
				<div class="xl3"></div>
				<div class="xl6 text-center">
					<h1 class="text-center">
						<span class="icon-check-circle text-yellow"></span> 派送订单成功了。
					</h1>
					<br />
					<p>
						<button class="button bg-green click_go_to_nav_button" data-trigger-id="#sub_see_to_be_send_order">
							<span class="icon-send"></span> 继续派送订单
						</button>
						<button class="button bg-green click_go_to_nav_button" data-trigger-id="#sub_see_to_be_received_order">
							<span class="icon-eye"></span> 去查看待收货的订单
						</button>
					</p>
				</div>
				<div class="xl3"></div>
			</div>
		</div>
	</div>
	<div class="xl2"></div>
</div>
<div style="display: none" id="time_temp_div"></div>

<script type="text/javascript">
	$(function()
	{

		$("#submit_send_out_order_button").click(function()
		{
			var express_order_id_input = $("#express_order_id_input").val();
			var orderExpressCompany = $("#orderExpressCompany").val();
			var orderExpressNumber = $("#orderExpressNumber").val();

			if (express_order_id_input.length <= 0 || orderExpressCompany.length <= 0 || orderExpressNumber.length <= 0)
			{
				alert("标有*的输入项都是必填项.")
				return false;
			}

			var tips = "";
			var tips_number = 1;
			$("#orderExpressCompany,#orderExpressNumber").each(function(i, dom)
			{
				var n = $(dom);
				if (new RegExp(n.attr("data-regex")).test(n.val()) == false)
				{
					tips += tips_number++ + " . \"" + n.val() + "\" 不满足输入要求;\n";
				}
			});

			if (tips.length > 0)
			{
				alert(tips + "\n请检查一下重新输入.");
				return false;
			}

			var submit_send_out_order_button_html = $("#submit_send_out_order_button").html();
			$.ajax(
			{
				url : "admin/m_add_express_info_do",
				type : "POST",
				dataType : "json",
				beforeSend : function(XMLHttpRequest)
				{
					$("#submit_send_out_order_button").attr("disabled", "disabled");
					$("#submit_send_out_order_button").html("正在提交快递信息中...");
				},
				data :
				{
					'order.orderId' : express_order_id_input,
					'order.orderExpressCompany' : orderExpressCompany,
					'order.orderExpressNumber' : orderExpressNumber
				},
				success : function(json, textStatus)
				{
					if (json.success == true)
					{
						$("#write_express_info_div").slideUp();
						$("#add_success_div").slideDown(function()
						{
							$(".admin").animate(
							{
								scrollTop : 0
							}, 0);
						});
					}
					else
					{
						alert(json.info);
					}
				},
				error : function(XMLHttpRequest, textStatus, errorThrown)
				{
					alert("提交失败，请仔细检查您的输入是否满足要求。");
				},
				complete : function(XMLHttpRequest, textStatus)
				{
					$("#submit_send_out_order_button").removeAttr("disabled");
					$("#submit_send_out_order_button").html(submit_send_out_order_button_html);
				}
			});
		});
	});
</script>